package quoc.phu;

import adapter.ContactAdapter;
import adapter.ContactList;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;

public class od_ContactActivity extends Activity {

	ExpandableListView expContact;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.od_activity_contact);
		ContactList contact = new ContactList();
		contact.init(ContactList.test);
		expContact = (ExpandableListView) findViewById(R.id.expContact);

		ExpandableListAdapter adapter = new ContactAdapter(this, contact);

		expContact.setAdapter(adapter);
		Log.d("Phu", "so con+" + expContact.getChildCount());
		registerForContextMenu(expContact);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.od_activity_contact, menu);
		return true;
	}

	public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {

    	super.onCreateContextMenu(menu, v, menuInfo);

    	ExpandableListView.ExpandableListContextMenuInfo info =    	(ExpandableListView.ExpandableListContextMenuInfo) menuInfo;

    	int type =    	ExpandableListView.getPackedPositionType(info.packedPosition);
    	int group =    	ExpandableListView.getPackedPositionGroup(info.packedPosition);
    	int child =    	ExpandableListView.getPackedPositionChild(info.packedPosition);

    	//Only create a context menu for child items

    	if(type==1){
			menu.add(0, 1, 0, "Chat");
			menu.add(0, 2, 0, "Xóa khỏi nhóm");			
    	}else{
    		menu.add(0,3,0,"Thêm thành viên");
    	}
	}

	public boolean onContextItemSelected(MenuItem menuItem) {
		ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuItem.getMenuInfo();
		int groupPos = 0, childPos = 0;
		int type = ExpandableListView.getPackedPositionType(info.packedPosition);
		if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
			groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
			childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
		}
		return super.onContextItemSelected(menuItem);

	}

}
